class CreateRelationships < ActiveRecord::Migration
  def self.up
    create_table :relationships, :id => false do |t|
      t.integer :source_ci_id, :destination_ci_id, :relationship_type_id, :null => false
      t.timestamps
    end
  
    execute "alter table relationships add constraint fk_source_ci
            foreign key (source_ci_id) references cis(id)"
    
    execute "alter table relationships add constraint fk_destination_ci
            foreign key (destination_ci_id) references cis(id)"
    
    execute "alter table relationships add constraint fk_relationship_type
             foreign key (relationship_type_id) references relationship_types(id)"
  end

  def self.down
    drop_table :relationships
  end
end